package by.kniazhych.core.controllers {
	
	/**
	 * ...
	 * @author Boutylin Mikhail
	 */
	
		import by.kniazhych.core.data.ApplicationDataBase;
		import by.kniazhych.core.events.ApplicationEvent;
		import by.kniazhych.core.view.frames.BaseFrameView;
		import by.vaukalak.core.controllers.AbstractController;
	import by.vaukalak.core.controllers.IBaseController;
	import flash.display.DisplayObject;
	

	
	public class BaseFrameController extends AbstractController{
		
		//--------------------------------------------------------------------------
		//
		//  PROPERTIES
		//
		//--------------------------------------------------------------------------
		
		protected var _frame:BaseFrameView;
		
		//--------------------------------------------------------------------------
		//
		//  CONSTRUCTOR
		//
		//--------------------------------------------------------------------------
		
		public function BaseFrameController(baseController:IBaseController) {
			super(baseController);
		}
		
		//--------------------------------------------------------------------------
		//
		//  PUBLIC METHODS
		//
		//--------------------------------------------------------------------------
		
		/**
		 * contstuct and enters the frame 
		 */
		
		public function constuctFrame(frame:BaseFrameView):void {
			_frame = frame;
			_frame.addEventListener(ApplicationEvent.FRAME_CHANGED, _onFrameChangeRequest);
		}
		
		/**
		 * exits the frame
		 */
		
		public function exitFrame():void {
			baseController.container.removeChild(_frame);
		}
		
		/**
		 * resume to the target frame
		 */
		
		public function enterFrame():void {
			baseController.container.addChild(_frame);
		}
		
		/**
		 * exit and destruct the frame
		 */
		
		public function desrtuctFrame():void {
			this.exitFrame();
		}
		
		//--------------------------------------------------------------------------
		//
		//  EVENT HANDLERS
		//
		//--------------------------------------------------------------------------
		
		private function _onFrameChangeRequest(e:ApplicationEvent):void {
			ApplicationDataBase(dataBase).currentApplicationFrame = e.frameToNavigate;
		}
		
	}

}